import csv

name_flag = False
data = {'name':'Pss'}
with open('/Users/ext.sunjiaqi12/Desktop/UI/Taro/Keels/TaroNativeHarmonyOS/keels_smaps/smaps_exe_file/com.example.taronative.keels_release_smaps_1762416666441487032.txt', 'r', encoding='utf-8') as file:
    name = file.readline().split('  ')[-1].strip()
    for line in file:
        if name_flag:
            name = line.split('  ')[-1].strip()
            name_flag = False
        if 'VmFlags' in line:
            name_flag = True
        if 'Pss:' in line and 'SwapPss' not in line:
            pss = int(line.split(' ')[-2])
            if name in data:
                data[name]+=pss
            else:
                data[name]=pss
print(data)

# 打开CSV文件进行写入
with open('keels_release_pss_question.csv', 'w', newline='', encoding='utf-8') as file:
    writer = csv.writer(file)

    # 写入数据
    for name in data:
        writer.writerow([name, data[name]])